#include <cstdio>
#include <set>

const int N = 50005;
int n, m;
int e_cnt, heads[N];

struct Edge {
  int v, nxt, w;
} e[N << 1];

inline void add(int u, int v, int w) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt, e[e_cnt].w = w;
}

int dfs(int x, int fa, int &len, int lim) {
  int res = 0;
  std::multiset<int> set;
  for (int i = heads[x], v; i; i = e[i].nxt) {
    if ((v = e[i].v) != fa) {
      int tmp;
      res += dfs(v, x, tmp, lim);
      tmp += e[i].w;
      if (tmp >= lim)
        ++res;
      else
        set.insert(tmp);
    }
  }
  len = 0;
  while (!set.empty()) {
    int tmp = *set.begin();
    set.erase(set.begin());
    std::multiset<int>::iterator iter = set.lower_bound(lim - tmp);
    if (iter != set.end()) {
      set.erase(iter);
      ++res;
    } else
      len = std::max(len, tmp);
  }
  return res;
}

inline bool check(int mid) {
  int tmp;
  return dfs(1, 0, tmp, mid) >= m;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("P5021 赛道修建.in", "r", stdin);
  freopen("P5021 赛道修建.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  for (int i = 1, a, b, w; i < n; ++i) {
    scanf("%d%d%d", &a, &b, &w);
    add(a, b, w), add(b, a, w);
  }
  int l = 0, r = 1e8, mid;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check(mid)) {
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  printf("%d", l - 1);
  return 0;
}